package com.demo.service.impl;

import java.util.List;

import com.demo.dao.UserMapper;
import com.demo.entity.EasyUIResult;
import com.demo.entity.User;
import com.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;



@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserMapper userMapper;

	@Override
	public EasyUIResult queryUserListByPage(Integer pageNum, Integer pageSize) {
		EasyUIResult easyUIResult = new EasyUIResult();
		// 分页获取用户信息
		PageHelper.startPage(pageNum, pageSize);
		List<User> userList = this.userMapper.queryUserAll();
		PageInfo<User> pageInfo = new PageInfo<>(userList);
		easyUIResult.setRows(userList);
		easyUIResult.setTotal(pageInfo.getTotal());
		return easyUIResult;
	}

	@Override
	public void addUsers(User user1, User user2) {
		this.userMapper.addUser(user1);
//		int i=1/0;
		this.userMapper.addUser(user2);
	}

	@Override
	public Boolean insertUser(User user) {
		int count = this.userMapper.addUser(user);
		if(count>0){
			return true;
		}
		return false;
	}

	@Override
	public Boolean login(String name, String password) {
		User user = this.userMapper.queryUserByName(name);
		if(user != null && user.getPassword().equals(password)){
			return true;
		}else{
			return false;
		}
	}

}
